<?php

/**
 * Customer Controller
 *
 * @author
 * @version
 */
require_once   BaseUtil::getModulePath("base")  .  '/controllers/BaseController.php';
require_once   BaseUtil::getModulePath("customer")  .  '/services/CustomerService.php';
require_once   BaseUtil::getModulePath("customer")  .  '/services/AgentService.php';
require_once   BaseUtil::getModulePath("customer")  .  '/forms/CustomerForm.php';
require_once   BaseUtil::getModulePath("common")  .  '/services/CommonService.php';
class Customer_AgentController extends BaseController {

    public function init(){
        parent::init();
	}
	
    public function showapplyAction(){
        $agentServ = new AgentService();
        $customers = $agentServ->getApplys($this->view, $_POST);
        $this->view->customers = $customers;
    }
    public function applydetailAction(){
        $this->view->script = array('agent.js','popup.js');
        $this->view->link = array('popup.css');
        $id = $this->_getParam('id');
        if(!$id){
            $this->_redirect('/customer/agent/showapply');
        }
        $agentServ = new AgentService();
        $details = $agentServ->getAgentDetailByID($id);
        if(empty($details)){
            $this->_redirect('/customer/agent/showapply');
        }
        $this->view->detail = $details;
        $this->view->ambassadors = $details['campus_id']?$agentServ->getDeputyByCampusID($details['campus_id'],$details['user_id']):"";
        $commonServ = new CommonService();
        $this->view->province = $commonServ->getAllProvince();
        $this->view->campuses = $commonServ->getCampusByDictId(1);
        
    }
    public function optionapplyAction(){
        $options = array();
        $options['applyStatus'] = HttpUtil::getPostString('applyStatus');
        $options['applyID'] = HttpUtil::getPostString('applyID');
        if($options['applyStatus'] == APPROVED_APPLY){
            $options['campusID'] = HttpUtil::getPostString('campusID');
            $options['is_ambassador'] = HttpUtil::getPostString('is_ambassador');
            $options['deputyID'] = HttpUtil::getPostString('deputyID');
        }
        $agentServ = new AgentService();
        $agentServ->optionApply($options);
        echo json_encode("sucess");exit;
    }
    public function rendercampusAction(){
        $this->_helper->layout->disableLayout ();
        $areaDictId = HttpUtil::getPostString('areaDictId');
        $commonServ = new CommonService();
        $this->view->campuses = $commonServ->getCampusByDictId($areaDictId);
    }
    public function renderambassadorAction(){
        $this->_helper->layout->disableLayout ();
        $campusID = HttpUtil::getPostString('campusID');
        $userID = HttpUtil::getPostString("userID");
        if(!$campusID){
            echo "<font color='red'>请选择高校!</font>";exit;
        }
        $agentServ = new AgentService();
        $this->view->ambassadors = $agentServ->getDeputyByCampusID($campusID,$userID);
    }
    public function deloneapplyAction(){
        $applyID = $this->_getParam('id');
        $agentServ = new AgentService();
        $agentServ->deleteOneApply($applyID);
        $this->_redirect('/customer/agent/showapply');
        exit;
    }

}